﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Royaumes_Libres.Database;

namespace Royaumes_Libres
{
    /// <summary>
    /// Gère les valeur par défaut des Mondes.
    /// </summary>
    /// <remarks>Patrick Chabot</remarks>
    public partial class ucWorldBase : System.Web.UI.UserControl
    {
        protected cWorldsAdminSetting pWorld;
        public cWorldsAdminSetting WorldBase { set { this.pWorld = value; } }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.InitControl();
        }

        /// <summary>
        /// Initialyse le usercontrol.
        /// </summary>
        /// <remarks>Patrick Chabot</remarks>
        protected void InitControl()
        {
            this.lblResources.Text = cText.GetText("Resources");
            this.lblWorks.Text = cText.GetText("Works");
            this.lblRate.Text = cText.GetText("Rate");

            this.lblInitMana.Text = cText.GetText("Mana");
            this.lblInitTimber.Text = cText.GetText("Timber");
            this.lblInitOre.Text = cText.GetText("Ore");
            this.lblInitFood.Text = cText.GetText("Food");
            this.lblInitPopulation.Text = cText.GetText("Population");

            this.lblInitDisciple.Text = cText.GetText("Disciple");
            this.lblInitLumberjack.Text = cText.GetText("Lumberjack");
            this.lblInitMiner.Text = cText.GetText("Miner");
            this.lblInitFarmer.Text = cText.GetText("Farmer");
            this.lblInitWorker.Text = cText.GetText("Worker");

            this.lblRateDisciple.Text = cText.GetText("Disciple");
            this.lblRateFarmer.Text = cText.GetText("Farmer");
            this.lblRateLumberjack.Text = cText.GetText("Lumberjack");
            this.lblRateMiner.Text = cText.GetText("Miner");
            this.lblRateWorker.Text = cText.GetText("Worker");


            this.txtInitMana.Text = this.pWorld.InitMana.ToString();
            this.txtInitTimber.Text = this.pWorld.InitTimber.ToString();
            this.txtInitOre.Text = this.pWorld.InitOre.ToString();
            this.txtInitFood.Text = this.pWorld.InitFood.ToString();
            this.txtInitPopulation.Text = this.pWorld.InitPopulation.ToString();

            this.txtInitDisciple.Text = this.pWorld.InitDisciple.ToString();
            this.txtInitLumberjack.Text = this.pWorld.InitLumberjack.ToString();
            this.txtInitMiner.Text = this.pWorld.InitMiner.ToString();
            this.txtInitFarmer.Text = this.pWorld.InitFarmer.ToString();
            this.txtInitWorker.Text = this.pWorld.InitWorker.ToString();

            this.txtRateDisciple.Text = this.pWorld.RateDisciple.ToString();
            this.txtRateFarmer.Text = this.pWorld.RateFarmer.ToString();
            this.txtRateLumberjack.Text = this.pWorld.RateLumberjack.ToString();
            this.txtRateMiner.Text = this.pWorld.RateMiner.ToString();
            this.txtRateWorker.Text = this.pWorld.RateWorker.ToString();
        }

        /// <summary>
        /// Enregistre le monde.
        /// </summary>
        /// <remarks>Patrick Chabot</remarks>
        public void Save()
        {
            this.pWorld.InitMana = int.Parse(this.txtInitMana.Text);
            this.pWorld.InitTimber = int.Parse(this.txtInitTimber.Text);
            this.pWorld.InitOre = int.Parse(this.txtInitOre.Text);
            this.pWorld.InitFood = int.Parse(this.txtInitFood.Text);
            this.pWorld.InitPopulation = int.Parse(this.txtInitPopulation.Text);

            this.pWorld.InitDisciple = int.Parse(this.txtInitDisciple.Text);
            this.pWorld.InitLumberjack = int.Parse(this.txtInitLumberjack.Text);
            this.pWorld.InitMiner = int.Parse(this.txtInitMiner.Text);
            this.pWorld.InitFarmer = int.Parse(this.txtInitFarmer.Text);
            this.pWorld.InitWorker = int.Parse(this.txtInitWorker.Text);

            this.pWorld.RateDisciple = decimal.Parse(this.txtRateDisciple.Text);
            this.pWorld.RateFarmer = decimal.Parse(this.txtRateFarmer.Text);
            this.pWorld.RateLumberjack = decimal.Parse(this.txtRateLumberjack.Text);
            this.pWorld.RateMiner = decimal.Parse(this.txtRateMiner.Text);
            this.pWorld.RateWorker = decimal.Parse(this.txtRateWorker.Text);

            this.pWorld.Save();
        }
    }
}